/*
 * File:   addListDialog.cpp
 * Author: E084412C
 *
 * Created on 29 janvier 2013, 15:18
 */

#include "addListDialog.h"
#include "modele/Date.h"
#include "QMessageBox"

addListDialog::addListDialog(accueil *parent) {
    widget.setupUi(this);
    
    parent_=parent;
    
    list<ListOfTask*> templates = parent_->getTemplates();
    for (std::list<ListOfTask*>::iterator it = templates.begin(); it != templates.end(); ++it) {
        ListOfTask *tmpListtemplate = *it;
        
        widget.comboTemplate->addItem(QString(tmpListtemplate->getName().c_str()));
        
    }
    
      
    
    QObject::connect(widget.addListBtn, SIGNAL(clicked()), this, SLOT(addListListener()));  
    
    
}

addListDialog::~addListDialog() {
}


void addListDialog::addListListener() {
    
    if(widget.listName->text()=="") {
        QMessageBox::information(this,"Erreur","Votre liste n'a pas de nom !",0,0,0);
        return;
    }
    
    QDate date = widget.calendarList->selectedDate();
    
    Date tmpDate = Date(date.day(),date.month(),date.year());
    
    string selectTemplate = "";
    if(widget.fromTemplate->isChecked()) {
        selectTemplate=widget.comboTemplate->currentText().toStdString();
    }
    
    //On ajout la liste à l'affichage
    parent_->addList(widget.listName->text().toStdString(), tmpDate, selectTemplate);
    
    
    
    //Permet de fermer la fenetre
    accept();
    
}